package com.mt.skyhoist;

import android.app.Application;

import com.mt.skyhoist.util.GlobalVariable;
import com.mt.skyhoist.util.Repository;
import com.mt.skyhoist.util.bean.DeviceModel;
import com.mt.skyhoist.util.bean.MixDatasModel;
import com.mt.skyhoist.util.user.DeviceModelSource;
import com.mt.skyhoist.util.user.MixDatasModelSource;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by daiguangtao on 2020/05/30.
 */

public class SkyhoistApplication extends Application {

    @Override
    public void onCreate() {

        System.out.println("SKYApplication onCreate");
        super.onCreate();

        getDatas();
    }

    // 初始化数据库
    private GlobalVariable mGlobalVariable;

    private void getDatas() {
        Repository.getInstance().init(this);
        mGlobalVariable = GlobalVariable.getinstance();

        List<DeviceModel> deviceList = DeviceModelSource.getInstance().getDeviceModel();
        if (deviceList == null) { // 首次创建
            System.out.println("首次创建");
            deviceList = new ArrayList<DeviceModel>();
        } else {
            System.out.println("非首次创建->" + deviceList.size());
        }

        mGlobalVariable.setDeviceList(deviceList);
        System.out.println("deviceList size->" + mGlobalVariable.getDeviceList().size());


        MixDatasModel mixDatas = MixDatasModelSource.getInstance().getDatas();
        if (mixDatas == null) {
            mixDatas = new MixDatasModel();
            MixDatasModelSource.getInstance().insert(mixDatas);
        }
        mGlobalVariable.setMixDatas(mixDatas);
    }
}
